//
//  SISSHouseProgressManageCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/19.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHouseProgressManageCell.h"


@interface SISSHouseProgressManageCell ()

@property (weak, nonatomic) IBOutlet UILabel *neighbourhoodAndPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaTypeLabel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *houseTagLabels;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelsViewHeight;
@property (weak, nonatomic) IBOutlet UILabel *progressTagLabel;
@property (weak, nonatomic) IBOutlet UILabel *trustCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *trustMethodLabel;
@property (weak, nonatomic) IBOutlet UIButton *redDotButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *trustCountHeightConstraint;

@end
@implementation SISSHouseProgressManageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // 设置委托人数边框
    self.trustCountLabel.layer.borderWidth = 1;
    self.trustCountLabel.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.trustCountLabel.layer.cornerRadius = 4;
    self.trustCountLabel.layer.masksToBounds = YES;
    
    // 设置委托方式边框
    self.trustMethodLabel.layer.borderWidth = 1;
    self.trustMethodLabel.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.trustMethodLabel.layer.cornerRadius = 4;
    self.trustMethodLabel.layer.masksToBounds = YES;
    
    for (int i = 0; i < 5; i++) {
        UILabel *label = self.houseTagLabels[i];
        label.hidden = YES;
    }
    self.labelsViewHeight.constant = 1;
}

- (void)setIsHistory:(BOOL)isHistory {
    _isHistory = isHistory;
    self.trustCountLabel.hidden = isHistory;
    self.trustMethodLabel.hidden = isHistory;
    self.trustCountHeightConstraint.constant = isHistory ? 0.01 : 20;
}

- (void)setHouseProgressModel:(SISSHouseProgressModel *)houseProgressModel {
    _houseProgressModel = houseProgressModel;
    
    self.neighbourhoodAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %@万",houseProgressModel.house.neighbourhood,houseProgressModel.house.price];
    self.regionAreaTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %@㎡ | %@",houseProgressModel.house.region,houseProgressModel.house.regionDetail,houseProgressModel.house.area,houseProgressModel.house.houseType];
    
    if (houseProgressModel.house.listTag.count > 0) {
        self.labelsViewHeight.constant = 30;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    for (UILabel *label in self.houseTagLabels) {
        
        label.hidden = YES;
    }
    
    for (int i = 0; i < houseProgressModel.house.listTag.count; i++) {
        UILabel *label = self.houseTagLabels[i];
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = houseProgressModel.house.listTag[i].tag;
        NSInteger colorIndex = houseProgressModel.house.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    self.redDotButton.hidden = !houseProgressModel.has_news;
    self.trustCountLabel.text = [NSString stringWithFormat:@"委托人数：%zd",houseProgressModel.entrustCount];
    self.trustMethodLabel.hidden = (houseProgressModel.entrustType != 2) || self.isHistory;
    self.trustMethodLabel.text = houseProgressModel.entrustType == 2 ? @"定向委托" : @"";
    
    NSArray *entrustArr = @[@"上传委托合同", @"上传委托合同", @"上传房屋状况说明书", @"实地看房", @"确定购买意向", @"上传卖家告知书", @"上传买家告知书", @"上传居间合同", @"上传买卖合同", @"系统核验网签合同", @"服务评价", @"已完成"];
    NSInteger count = self.isHistory ? 2 : 1;
    if (houseProgressModel.progress >= 11) {
        count = 1;
    }
//    NSInteger index = (houseProgressModel.progress - count) > 10 ? 10 : (houseProgressModel.progress - count);
    NSInteger index = houseProgressModel.progress - count;
    self.progressTagLabel.text = entrustArr[index];
    
}

@end
